#include<iostream>

using namespace std;
int n, m;
const int N = 1e5 + 10;
using ll = long long;
ll a[N];

bool check(int x)
{
    int cnt = 0;
    int sum = 0;
    for (int i = 1; i <= n; i++)
    {
        sum += a[i];
        if (sum > x)
        {
            cnt++;
            sum = a[i];
        } 
    }
    return cnt + 1 <= m;
}
int main()
{
    cin >> n >> m;
    ll Max = 0, sum = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        Max = max(Max, a[i]);
        sum += a[i];
    } 
    ll l = Max, r = sum;
    while (l < r)
    {
        int mid = (r + l) / 2;
        if (check(mid)) r = mid;
        else l = mid + 1;
    }
    cout << l << endl;
    return 0;
}